package com.fdb.efp.nls.api.rest;

import com.fdb.basic.framework.core.constant.ResponseData;
import com.fdb.basic.framework.web.controller.AbstractController;
import com.fdb.efp.nls.service.facade.PrdChangeRecordService;
import com.fdb.efp.nls.service.vo.PrdChangeRecordVO;
import com.fdb.efp.e4a.service.facade.SRoleDataRuleService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/api")
public class PrdChangeRecordController extends AbstractController {

	@Autowired
	@Qualifier("prdChangeRecordService")
	private PrdChangeRecordService prdChangeRecordService;

	@Autowired
	@Qualifier("sRoleDataRuleService")
	private SRoleDataRuleService sRoleDataRuleService;

	/**
	 * 列表数据查询
	 * 
	 * @param page
	 * @param size
	 * @return
	 */
	@RequestMapping(value = "/prd/change/records", method = RequestMethod.POST)
	public @ResponseBody ResponseData<List<PrdChangeRecordVO>> queryPrdChangeRecordAll(@RequestBody PrdChangeRecordVO vo) {
		setUserInfoToVO(vo);
		List<PrdChangeRecordVO> outputVo = prdChangeRecordService.queryAllByBizSerno(vo);
		// 根据用户角色获取用户权限方案
		/** 【不符合switch规范】
		String dataAuthority = sRoleDataRuleService.getDataRuleType(httpRequest.getRequestURI(), getUserRoles());
		List<PrdChangeRecordVO> outputVo = null;
		DataRuleType dataRuleType = DataRuleType.getDataRuleType(dataAuthority);

		// 根据权限方案调用不同的方案进行数据查询
		switch (dataRuleType) {
		case Owner:
			outputVo = prdChangeRecordService.queryAllByBizSerno(vo);
			break;
		【未实现的方法】
		case CurrOrg:
			outputVo = prdChangeRecordService.queryAllCurrOrg(vo);
			break;
		case CurrDownOrg:
			outputVo = prdChangeRecordService.queryAllCurrDownOrg(vo);
			break;
		default:
			outputVo = prdChangeRecordService.queryAllByBizSerno(vo);
			break;
		}*/
		return getResponseData(outputVo);

	}

	/**
	 * 根据bizSerno流水号查询产品申请规则关联信息
	 * 
	 * @param page
	 * @param size
	 * @return
	 */
	@RequestMapping(value = "/prd/change/recordsBySerno", method = RequestMethod.POST)
	public @ResponseBody ResponseData<List<PrdChangeRecordVO>> queryAllByBizSerno(@RequestBody PrdChangeRecordVO vo) {
		List<PrdChangeRecordVO> outputVo = prdChangeRecordService.queryAllByBizSerno(vo);
		return getResponseData(outputVo);
	}

	/**
	 * 新增数据
	 * 
	 * @param inPrdChangeRecordVo
	 * @return
	 */
	@RequestMapping(value = "/prd/change/record", method = RequestMethod.POST)
	public @ResponseBody ResponseData<Integer> insertPrdChangeRecord(@RequestBody PrdChangeRecordVO inPrdChangeRecordVo) {
		int outputVo = prdChangeRecordService.insertPrdChangeRecord(inPrdChangeRecordVo);
		return getResponseData(outputVo);

	}
}
